RladiesBari Hands-on session

Sara Iacozza

RLadies Meetup - 7 Maggio, 2019

Due cose sui dati

  • Dati comportamentali reali
  • Variabili dipendenti: accuratezza & tempi di reazione
  • 2 x 2 factorial design, within-subject
  • Struttura random: Partecipanti

Carichiamo i pacchetti che ci serviranno (install.packages + library)

Carichiamo i dati e diamo un’occhiata

##     Subject          Block           Trial       SpeakerPhoto      
##  Min.   : 1.00   Min.   :1.000   Min.   : 1.00   Length:7280       
##  1st Qu.:12.00   1st Qu.:1.000   1st Qu.:20.75   Class :character  
##  Median :24.00   Median :1.000   Median :40.50   Mode  :character  
##  Mean   :23.58   Mean   :1.495   Mean   :40.50                     
##  3rd Qu.:35.00   3rd Qu.:2.000   3rd Qu.:60.25                     
##  Max.   :46.00   Max.   :2.000   Max.   :80.00                     
##      Logo            Condition          TargetButton Button_Response
##  Length:7280        Length:7280        Min.   :2.0   Min.   :0.000  
##  Class :character   Class :character   1st Qu.:2.0   1st Qu.:2.000  
##  Mode  :character   Mode  :character   Median :2.5   Median :2.000  
##                                        Mean   :2.5   Mean   :2.478  
##                                        3rd Qu.:3.0   3rd Qu.:3.000  
##                                        Max.   :3.0   Max.   :3.000  
##     Accuracy           RTs           
##  Min.   :0.0000   Min.   :  -1639.0  
##  1st Qu.:1.0000   1st Qu.:    717.8  
##  Median :1.0000   Median :    847.0  
##  Mean   :0.9374   Mean   :   9544.4  
##  3rd Qu.:1.0000   3rd Qu.:   1021.0  
##  Max.   :1.0000   Max.   :2100000.0

Strutturiamo i dati!

##   Participant   Block        Trial       Group_Membership
##  1      : 160   1:3643   Min.   : 1.00   Ingroup :3612   
##  2      : 160   2:3575   1st Qu.:21.00   Outgroup:3606   
##  4      : 160            Median :41.00                   
##  5      : 160            Mean   :40.53                   
##  6      : 160            3rd Qu.:61.00                   
##  7      : 160            Max.   :80.00                   
##  (Other):6258                                            
##        Condition       Accuracy           RTs        
##  matching   :3614   Min.   :0.0000   Min.   :  98.0  
##  mismatching:3604   1st Qu.:1.0000   1st Qu.: 716.0  
##                     Median :1.0000   Median : 844.0  
##                     Mean   :0.9417   Mean   : 888.7  
##                     3rd Qu.:1.0000   3rd Qu.:1015.0  
##                     Max.   :1.0000   Max.   :2097.0  
## 

Distribuzione Accuracy

Non sembrano esserci molti errori…

Distribuzione RTs

(solitamente skewed)

Predicted Hypotheses:

  1. Le persone sono piu’ veloci a rispondere ad un’associazione corretta che incorreta : –> (RTs) matching<mismatching

  2. Le persone son piu’ veloci a rispondere ad un’associazione in-group che out-group : –> (RTs) in-group Group Membership x Condition

Distribuzione RTs per condizione

Statisticamente parlando…

gif

Semplice regressione lineare

lm(log10(RTs)~GroupMembership*Condition (+ Block))

+ Random effects

lmer(log10(RTs)~GroupMembershipxCondition (+ Block)+ (1+GroupMembershipxCondition|Participant))

Output

## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: 
## log10(RTs) ~ Condition * Group_Membership + Block + (1 + Condition |  
##     Participant)
##    Data: PMT
## Control: lmerControl(optCtrl = list(optimizer = "bobyqa", maxfun = 1e+09))
## 
## REML criterion at convergence: -13833.2
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.6572 -0.6462 -0.0642  0.6075  3.5722 
## 
## Random effects:
##  Groups      Name         Variance  Std.Dev. Corr
##  Participant (Intercept)  0.0043895 0.06625      
##              Condition2-1 0.0003631 0.01906  0.23
##  Residual                 0.0070104 0.08373      
## Number of obs: 6657, groups:  Participant, 46
## 
## Fixed effects:
##                                    Estimate Std. Error         df t value
## (Intercept)                       2.931e+00  9.824e-03  4.499e+01 298.356
## Condition2-1                      3.793e-02  3.490e-03  4.367e+01  10.869
## Group_Membership2-1               2.866e-02  2.054e-03  6.567e+03  13.953
## Block2-1                         -1.422e-02  2.061e-03  6.567e+03  -6.898
## Condition2-1:Group_Membership2-1 -4.034e-02  4.109e-03  6.564e+03  -9.819
##                                  Pr(>|t|)    
## (Intercept)                       < 2e-16 ***
## Condition2-1                     5.29e-14 ***
## Group_Membership2-1               < 2e-16 ***
## Block2-1                         5.79e-12 ***
## Condition2-1:Group_Membership2-1  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) Cnd2-1 G_M2-1 Blc2-1
## Conditin2-1  0.183                     
## Grp_Mmbr2-1  0.001 -0.008              
## Block2-1     0.001 -0.002  0.004       
## C2-1:G_M2-1 -0.001  0.004  0.014  0.003
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 2.93 0.01 44.99 298.36 0
Condition2-1 0.04 0.00 43.67 10.87 0
Group_Membership2-1 0.03 0.00 6566.77 13.95 0
Block2-1 -0.01 0.00 6567.31 -6.90 0
Condition2-1:Group_Membership2-1 -0.04 0.00 6563.77 -9.82 0
  log10(RTs)
Predictors Estimates CI p
(Intercept) 2.93 2.91 – 2.95 <0.001
Condition2-1 0.04 0.03 – 0.04 <0.001
Group_Membership2-1 0.03 0.02 – 0.03 <0.001
Block2-1 -0.01 -0.02 – -0.01 <0.001
Condition2-1:Group_Membership2-1 -0.04 -0.05 – -0.03 <0.001
Random Effects
σ2 0.01
τ00 Participant 0.00
τ11 Participant.Condition2-1 0.00
ρ01 Participant 0.23
ICC Participant 0.39
Observations 6657
Marginal R2 / Conditional R2 0.060 / 0.426

Data Viz (model output)

Da cosa deriva l’interazione?: pairwise comparisons

L’effetto di Condition e’ maggiore con In-group, pero’..

## $emmeans
## Group_Membership = Ingroup:
##  Condition   emmean      SE  df asymp.LCL asymp.UCL
##  matching      2.89 0.00976 Inf      2.87      2.91
##  mismatching   2.95 0.01039 Inf      2.93      2.97
## 
## Group_Membership = Outgroup:
##  Condition   emmean      SE  df asymp.LCL asymp.UCL
##  matching      2.94 0.00977 Inf      2.92      2.96
##  mismatching   2.95 0.01039 Inf      2.93      2.97
## 
## Results are averaged over the levels of: Block 
## Degrees-of-freedom method: asymptotic 
## Results are given on the log10 (not the response) scale. 
## Confidence level used: 0.95 
## 
## $contrasts
## Group_Membership = Ingroup:
##  contrast               estimate      SE  df z.ratio p.value
##  matching - mismatching  -0.0581 0.00404 Inf -14.371 <.0001 
## 
## Group_Membership = Outgroup:
##  contrast               estimate      SE  df z.ratio p.value
##  matching - mismatching  -0.0178 0.00406 Inf  -4.379 <.0001 
## 
## Results are averaged over the levels of: Block

Da cosa deriva l’interazione?: pairwise comparisons 2

L’effetto di In-group e’ nei maggiormente nei matching trials…

## $emmeans
## Condition = matching:
##  Group_Membership emmean      SE  df asymp.LCL asymp.UCL
##  Ingroup            2.89 0.00976 Inf      2.87      2.91
##  Outgroup           2.94 0.00977 Inf      2.92      2.96
## 
## Condition = mismatching:
##  Group_Membership emmean      SE  df asymp.LCL asymp.UCL
##  Ingroup            2.95 0.01039 Inf      2.93      2.97
##  Outgroup           2.95 0.01039 Inf      2.93      2.97
## 
## Results are averaged over the levels of: Block 
## Degrees-of-freedom method: asymptotic 
## Results are given on the log10 (not the response) scale. 
## Confidence level used: 0.95 
## 
## $contrasts
## Condition = matching:
##  contrast           estimate      SE  df z.ratio p.value
##  Ingroup - Outgroup -0.04883 0.00288 Inf -16.929 <.0001 
## 
## Condition = mismatching:
##  contrast           estimate      SE  df z.ratio p.value
##  Ingroup - Outgroup -0.00849 0.00293 Inf  -2.901 0.0037 
## 
## Results are averaged over the levels of: Block

Diagnostics

Diagnostics - bad example

Diagnostics 2

Diagnostics 2 - bad

Risultati:

I dati hanno supportato le nostre ipotesi. 1. I partecipanti hanno classificato piu’ velocemente un’associazione corretta che incorretta.

Risultati 2:

  1. I partecipanti hanno classificato piu’ velocemente un’associazione ingroup che outgrop

Risultati 3:

E l’interazione dice che c’e’ una differenza tra le condizioni di matching and mismatching per quanto riguarda l’effetto di Group Membership.

Attraverso l’analisi di simple effects (pairwise comparisons), abbiamo visto che i partecipanti erano piu’ veloci con le associazioni in-group ma maggiormente quando un’associazione era corretta.

Take-home messagge:

I mixed-effect models sono importantissimi quando ci sono intra e inter variabilita’ perche’ aiutano a ridurre la possibilita’ di attribuire importanza a cio’ che non ne ha.

GRAZIE MILLE!

Questions?